<?php
if (!defined('BASEPATH'))
    exit('No direct script access allowed');

class Com_model extends CI_Model{
    
    
    public function __construct() {
        parent::__construct();
    }
    //nhap du lieu
    public function insertCom($mang){
        if (is_array($mang)) {
            $data = array(
                "FID" => $mang["fid"],
                "Name" => $mang["name"],
                "CID" => $mang["id"],
                "CmContent"=> $mang["cm"],
                "date" => $mang["curdate"]
            );
            $q = $this->db->insert("comment",$data);
            if($q){
                return TRUE;
            }else{
                return FALSE;
            }
        }
    }
    //lay du lieu
    public function getCom($fid){
        if(isset($fid) && $fid != NULL){
            $q = $this->db->where("FID", $fid)->order_by("CmID","desc")->get("comment");
            if($q->num_rows() > 0){
                return $q;
            }
            return $q;
        }
    }
    
    public function getAllCom(){
        $q = $this->db->select("comment.FID,Name,CmID,CmContent,date,FName")
                ->from("comment")
                ->join("flowers", "flowers.FID = comment.FID")
                ->group_by("comment.FID")
                ->get();
        if($q->num_rows() > 0){
            return $q;
        }else{
            return FALSE;
        }
    }
    //xoa comment trong csdl
    public function delCom($comID){
        if(isset($comID)){
            $q = $this->db->delete("comment", array("CmID"=>$comID));
            if($q){
                return TRUE;
            }else{
                return FALSE;
            }
        }else{
            return FALSE;
        }
        
    }
}
?>
